<?php

namespace App\Modules\Apicrzs\Http\Controllers\Intake;

use App\Modules\Apicrzs\Http\Controllers\BaseApicrzsController;
use App\Modules\Apicrzs\Http\Requests\UserWaterCardRequest;
use App\Modules\Apicrzs\Services\Users\UserWaterCardServices;
use App\Traits\CryptAES;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\Request;

class UserWaterCardController extends BaseApicrzsController
{

    public function __construct(UserWaterCardServices $service)
    {
        $token =  \request()->header('token');
        $user_info = CryptAES::decryptToken($token,'user_grzq');
        $this->user_id = $user_info['data']['user_id']??0;

        $this->service = $service;
    }

    public function getCardInfo(Request $request,UserWaterCardServices $cardServices):JsonResponse
    {
        $params = $request->all();
        $result = $this->service->getCardInfo($params);
        if ($result){
            return $this->sendApiSuccess($result, $this->service->getError());
        }else{
            return $this->sendApiError($this->service->getError());
        }
    }
    // 添加水卡 / 绑定水卡
    public function create(UserWaterCardRequest $request): JsonResponse
    {
        $result = $this->service->createBinding($request->all());
        if ($result){
            return $this->sendApiSuccess($result, $this->service->getError());
        }else{
            return $this->sendApiError($this->service->getError());
        }
    }
    // 添加水卡 / 绑定水卡
    public function update(UserWaterCardRequest $request): JsonResponse
    {
        $result = $this->service->updateBinding($request->all());
        if ($result){
            return $this->sendApiSuccess($result, $this->service->getError());
        }else{
            return $this->sendApiError($this->service->getError());
        }
    }
    // 解绑 / 水卡
    public function deleteBinding(UserWaterCardRequest $request): JsonResponse
    {
        $result = $this->service->deleteBinding($request->all());
        if ($result){
            return $this->sendApiSuccess($result, 200,$this->service->getError());
        }else{
            return $this->sendApiError($this->service->getError());
        }
    }
    //检测水卡 信息  - 骏达
    public function getICBalance(UserWaterCardRequest $request): JsonResponse
    {
        $result = $this->service->getICBalance($request->all());
        if ($result){
            return $this->sendApiSuccess($result, 200,$this->service->getError());
        }else{
            return $this->sendApiError($this->service->getError());
        }
    }


    public function getCardList(Request $request,UserWaterCardServices $cardServices):JsonResponse
    {
        $params = $request->all();
        $result = $this->service->getCardList($params);

        return $this->sendApiSuccess($result, $this->service->getError());
    }
}
